1 00:00:00,510 --> 00:00:05,370 Alrighty, now we get to move on to our local script for the SCP 294 GUI. 2 00:00:05,400 --> 00:00:10,200 This should be pretty straightforward, as you've likely interacted with GUI and GUI events in the past. 3 00:00:10,200 --> 00:00:14,160 And if you've been in my previous course, you'll be familiar with GUIs and their events. 4 00:00:14,310 --> 00:00:18,900 This guy in particular is going to be the one that contains the keyboard, as well as the display to 5 00:00:18,900 --> 00:00:21,090 show what the player is typing for their drink. 6 00:00:21,090 --> 00:00:25,470 So if I go ahead and enable visibility here, we're just going to have this on their screen. 7 00:00:25,470 --> 00:00:30,000 And whenever they type something in, we're going to show that text here on this little screen. 8 00:00:30,760 --> 00:00:35,110 So inside of our local script for the GUI, we're just going to need three services. 9 00:00:35,110 --> 00:00:37,480 One is going to be the player service. 10 00:00:39,430 --> 00:00:43,360 We're going to need the sound service so we could get access to the guy. 11 00:00:43,390 --> 00:00:44,320 Sounds. 12 00:00:45,640 --> 00:00:50,350 We're also going to need replicated storage as well, so we can get access to some of those assets in 13 00:00:50,350 --> 00:00:50,860 there. 14 00:00:53,480 --> 00:00:55,850 And then let's go ahead and fill out some variables. 15 00:00:55,880 --> 00:00:58,190 I first want to get access to our drink class. 16 00:00:58,190 --> 00:01:01,400 This is going to be our local drink class that exists on the client. 17 00:01:01,400 --> 00:01:03,770 So we're going to require within replicated storage. 18 00:01:03,770 --> 00:01:07,670 We're going to wait for the SCP 294 assets folder to replicate. 19 00:01:07,670 --> 00:01:11,210 And we're going to require our drink class for the client. 20 00:01:11,840 --> 00:01:15,650 And then we're also going to have a reference to our request drink event. 21 00:01:16,630 --> 00:01:22,510 And we'll have that in replicated storage, same folder, and we'll wait for the request remote function. 22 00:01:23,380 --> 00:01:27,040 We'll have a reference to the guy itself, which is just script dot parent. 23 00:01:27,610 --> 00:01:31,660 We'll have a reference to the local player which is just players dot local player. 24 00:01:31,900 --> 00:01:35,950 And then we'll also have a reference to the local character of this player. 25 00:01:35,950 --> 00:01:38,110 So we can just do player dot character. 26 00:01:38,110 --> 00:01:44,950 Or if the player's character hasn't been added yet, we can do or player dot character added and we'll 27 00:01:44,950 --> 00:01:49,480 wait for this event and this event will return to us the character and store it in our variable. 28 00:01:49,660 --> 00:01:54,520 I want to have a reference to that display text or the output box that is in our guy. 29 00:01:54,550 --> 00:01:59,110 So I'll call this output box and it's inside of our guy. 30 00:01:59,110 --> 00:02:02,470 We're going to wait for the frame to replicate just in case. 31 00:02:02,470 --> 00:02:04,810 We're going to wait for the image label in there. 32 00:02:04,810 --> 00:02:09,850 And inside this image label there is a frame called output or a text label called output. 33 00:02:09,850 --> 00:02:11,920 And that's where we're going to put our text. 34 00:02:12,340 --> 00:02:15,430 And I want to refer to all the buttons that are inside of our GUI. 35 00:02:15,430 --> 00:02:19,180 And we can just do that by doing GUI, dot frame, dot image label. 36 00:02:19,180 --> 00:02:22,450 And we'll get every single child that is in our image label. 37 00:02:22,450 --> 00:02:23,920 So inside of our GUI. 38 00:02:23,950 --> 00:02:27,070 Here we have a bunch of buttons. 39 00:02:27,070 --> 00:02:32,710 In each of these buttons are for all the numbers and all of the letters that we could input into our 40 00:02:32,710 --> 00:02:33,580 drink machine. 41 00:02:33,580 --> 00:02:37,810 So that means we're going to have to connect a function to every single one of these text buttons. 42 00:02:37,810 --> 00:02:41,560 And, you know, take their letter and put that in the output box. 43 00:02:42,070 --> 00:02:44,860 I also want to have a reference to the click sound. 44 00:02:45,670 --> 00:02:46,150 For. 45 00:02:46,150 --> 00:02:50,770 When we click a button on our guy, we can play that click sound so it's in sound service. 46 00:02:50,770 --> 00:02:57,730 We'll wait for the SCP 294 sounds to replicate, wait for the guy folder, and we're going to wait for 47 00:02:57,730 --> 00:02:59,230 the button sound. 48 00:03:00,000 --> 00:03:07,710 And then I'm going to create two variables, one called original walk speed and one called original 49 00:03:07,710 --> 00:03:09,090 jump height. 50 00:03:09,210 --> 00:03:15,060 And we're going to store these in these variables because when the player opens the GUI on their screen, 51 00:03:15,060 --> 00:03:18,870 I want to set the player's walk speed to zero and their jump height to zero. 52 00:03:18,900 --> 00:03:22,200 That way they can't move while they have the GUI open. 53 00:03:22,200 --> 00:03:27,180 And then once they close the GUI, we'll set their walk speed and their jump height back to their original 54 00:03:27,180 --> 00:03:30,030 so we can set this equal to the local character. 55 00:03:30,390 --> 00:03:32,520 I'm going to wait for the humanoid. 56 00:03:33,170 --> 00:03:35,960 And we're going to get the walk speed. 57 00:03:36,080 --> 00:03:39,320 And then we could do the same thing for the local character. 58 00:03:40,220 --> 00:03:42,890 Humanoid dot jump height. 59 00:03:43,340 --> 00:03:48,020 And it should be jump height unless you have a different setting set inside of starter player. 60 00:03:48,020 --> 00:03:52,610 So inside of starter player here there's a section called character jump settings. 61 00:03:52,610 --> 00:03:57,350 Typically before they had it where you had to use a property called jump power. 62 00:03:57,350 --> 00:04:00,770 But I believe now they have changed it to use a default called jump height. 63 00:04:00,770 --> 00:04:05,180 But if you still have this enabled, then instead the value is going to be jump power. 64 00:04:05,180 --> 00:04:10,070 So you'll have to change this to jump power instead of jump height. 65 00:04:10,250 --> 00:04:13,010 But I'm just going to use the default of jump height. 66 00:04:13,750 --> 00:04:16,420 And actually I want to have a reference to the other event as well. 67 00:04:16,450 --> 00:04:17,530 Our comms event. 68 00:04:17,530 --> 00:04:23,830 So replicated storage get our assets folder and we'll wait for the communication remote event to replicate. 69 00:04:24,600 --> 00:04:28,140 And then I'm going to use one variable as our debounce. 70 00:04:28,500 --> 00:04:33,030 And this debounce is going to be for when we request to dispense a drink, we're going to output the 71 00:04:33,030 --> 00:04:34,440 text like dispensing. 72 00:04:34,440 --> 00:04:38,610 And we don't want the player to be able to input any more text into the display. 73 00:04:38,610 --> 00:04:43,500 So we'll make sure to enable a Debounce and then disable it once the player gets their drink. 74 00:04:43,770 --> 00:04:46,980 Now for our GUI, I want to have a few functions. 75 00:04:46,980 --> 00:04:50,610 One function I'll have to close the GUI. 76 00:04:50,940 --> 00:04:56,490 I'm going to have a function for every single button or text button inside of our guy, so I'll just 77 00:04:56,490 --> 00:04:58,410 call it on button clicked. 78 00:04:59,950 --> 00:05:04,420 And then I want to have a function for dispensing the drink. 79 00:05:04,420 --> 00:05:06,160 So we'll call it dispense drink. 80 00:05:08,550 --> 00:05:14,730 And then one last function we'll need is I'm going to call it on child added to backpack. 81 00:05:14,820 --> 00:05:19,560 And this is going to listen for when a child or a tool gets added to the player's backpack. 82 00:05:19,560 --> 00:05:24,780 And if it's a drink cup then we're going to create or get a new drink object for our drink class. 83 00:05:25,550 --> 00:05:29,930 Now some handlers will need of course is going to be for the comms event. 84 00:05:30,760 --> 00:05:35,290 And on client event, we're going to connect a Lambda function to this event. 85 00:05:35,290 --> 00:05:37,780 And again we're going to have an action. 86 00:05:37,960 --> 00:05:42,310 And in fact, the only thing I want to do here on the GUI is I want to listen for when an action is 87 00:05:42,310 --> 00:05:47,350 given called we could do something like if action is equal to enable GUI. 88 00:05:47,350 --> 00:05:52,870 So if I go up to a drink machine and enable the proximity prompt, then the server is going to, you 89 00:05:52,870 --> 00:05:58,630 know, verify some stuff and then tell me to enable the GUI on my end, because the server is the one 90 00:05:58,630 --> 00:06:03,400 that's collecting all of the different drink machines and listening to the proximity prompts inside 91 00:06:03,400 --> 00:06:03,970 of them. 92 00:06:04,330 --> 00:06:08,320 So when the specific action gets requested, we can actually have another function. 93 00:06:09,190 --> 00:06:11,170 We can call it open GUI. 94 00:06:11,560 --> 00:06:14,470 And this will be responsible for opening our GUI. 95 00:06:14,470 --> 00:06:18,130 And what we could do here is we could do GUI dot enabled. 96 00:06:18,130 --> 00:06:19,330 Make sure that's set to true. 97 00:06:19,330 --> 00:06:23,620 It should be set to true by default right here. 98 00:06:23,620 --> 00:06:26,230 But just in case it isn't we're going to set it to true. 99 00:06:26,440 --> 00:06:30,430 We're going to do GUI dot frame, set its visibility equal to true. 100 00:06:30,430 --> 00:06:34,300 Because by default the visibility of our frame is set to false. 101 00:06:35,910 --> 00:06:40,770 And then from this point, we could set the original walk speed equal to the local character. 102 00:06:41,450 --> 00:06:45,740 That humanoid dot walk speed. 103 00:06:46,070 --> 00:06:48,740 Same thing with the jump height. 104 00:06:53,580 --> 00:06:57,900 And since the guy is opening on our screen, we want to freeze the player in place. 105 00:06:57,900 --> 00:07:04,260 And the easy way to do that would be to just to access the local player and set the humanoid dot walk 106 00:07:04,260 --> 00:07:08,640 speed property equal to zero, along with the jump height. 107 00:07:13,540 --> 00:07:16,420 And this will stop the player from being able to move around. 108 00:07:17,030 --> 00:07:19,010 So we can call this function right here. 109 00:07:19,010 --> 00:07:22,100 When the server tells us to open a GUI on our screen. 110 00:07:22,100 --> 00:07:26,420 Otherwise, the next thing I'm going to do in this section is I'm going to loop through every single 111 00:07:26,420 --> 00:07:31,580 button that is inside of that buttons table we created. 112 00:07:31,760 --> 00:07:37,550 So for every single thing that exists in that table, which will include all of the children of our 113 00:07:37,550 --> 00:07:38,210 image label. 114 00:07:38,210 --> 00:07:42,620 So all of these things, we want to first verify a few things. 115 00:07:42,620 --> 00:07:46,460 First if the string dot length. 116 00:07:47,350 --> 00:07:49,990 Of this button dot name. 117 00:07:50,380 --> 00:07:53,740 If it's greater than one. 118 00:07:54,430 --> 00:07:59,860 Then we're just going to continue looping, because we only want to care about the specific buttons 119 00:07:59,860 --> 00:08:02,350 that have a name that's only one character long. 120 00:08:02,350 --> 00:08:03,640 We don't want to worry about this. 121 00:08:03,640 --> 00:08:07,660 We don't want to worry about this or any of these other ones. 122 00:08:07,660 --> 00:08:12,610 So if the length of the name of this button is greater than one, then we're just going to continue 123 00:08:12,610 --> 00:08:13,180 looping. 124 00:08:13,750 --> 00:08:18,490 Otherwise, another thing we got to make sure is if this item is a text button. 125 00:08:18,490 --> 00:08:24,070 So if it is not a text button is a text button. 126 00:08:26,080 --> 00:08:27,910 Then we're going to continue looping. 127 00:08:28,600 --> 00:08:33,700 Otherwise, if it's a button and it's one of these ones that have a one character name, then what we 128 00:08:33,700 --> 00:08:35,770 could do is we could do button. 129 00:08:35,770 --> 00:08:40,210 Listen to the event mouse button one up. 130 00:08:41,170 --> 00:08:44,320 And we can connect a lambda function. 131 00:08:44,560 --> 00:08:48,460 And this function is just going to call the on button clicked function. 132 00:08:48,460 --> 00:08:52,450 And in fact we'll pass the button itself to this function. 133 00:08:52,450 --> 00:08:56,140 So in here we can have a parameter for a button. 134 00:08:58,030 --> 00:08:58,630 All right. 135 00:08:58,630 --> 00:09:04,240 The next thing I want to do is I want to listen for each of the buttons that weren't set up by this 136 00:09:04,240 --> 00:09:09,160 for loop, which includes this button, this button, this button and this button. 137 00:09:09,160 --> 00:09:12,130 So we could do GUI dot frame. 138 00:09:12,910 --> 00:09:15,610 Dot image label will wait for. 139 00:09:15,610 --> 00:09:18,760 Let's do the exit button first, just in case it hasn't replicated. 140 00:09:18,760 --> 00:09:23,020 And again we'll listen to mouse button one up. 141 00:09:24,850 --> 00:09:28,090 And we're going to connect a lambda function to this. 142 00:09:29,270 --> 00:09:32,900 First we're going to check if the Debounce is currently active. 143 00:09:32,900 --> 00:09:37,220 So if the Debounce is active then we're just going to return end. 144 00:09:37,370 --> 00:09:42,710 Otherwise, when the player hits the exit button we just want to close our guy. 145 00:09:43,070 --> 00:09:45,710 So that's another thing we could fill out real quick here. 146 00:09:45,710 --> 00:09:47,810 What do we want to do to close the guy? 147 00:09:47,840 --> 00:09:52,610 Well we can set the guy dot frame dot visibility equal to false. 148 00:09:52,610 --> 00:09:56,870 We can set the output box dot text equal to nothing. 149 00:09:56,870 --> 00:10:00,830 That way we can clear any previous message that was in the output box. 150 00:10:01,310 --> 00:10:09,020 And then we could set the local characters dot humanoid, dot walk speed back to the original walk speed 151 00:10:09,020 --> 00:10:12,860 and do the same thing for the jump height. 152 00:10:17,800 --> 00:10:21,640 And we can set Debounce back to false just in case we need to. 153 00:10:21,880 --> 00:10:25,120 We can also go ahead and fill out the on button clicked function as well. 154 00:10:25,120 --> 00:10:28,870 So what do we want to do when one of the buttons on our keyboard gets clicked? 155 00:10:28,870 --> 00:10:35,410 Well, what we could do is of course first check if there is a debounce because we don't want to input 156 00:10:35,410 --> 00:10:40,660 or add anything to our output text label if the Debounce is activated. 157 00:10:40,660 --> 00:10:44,470 However, if it isn't, then we can play that click sound. 158 00:10:46,050 --> 00:10:56,160 And then what we could do is I want to verify that we haven't put too many different, um, characters 159 00:10:56,160 --> 00:11:03,270 into the output text label, so we can actually set a limit to however many text or characters we can 160 00:11:03,270 --> 00:11:06,750 put inside of the output box, because we don't want to put way too many. 161 00:11:06,780 --> 00:11:12,120 We got to we might want to set a limit so we can actually create a constant one. 162 00:11:12,120 --> 00:11:17,700 I'm going to call it Max cars for max characters, and we can set a max character length of something 163 00:11:17,700 --> 00:11:18,930 like 25. 164 00:11:19,200 --> 00:11:25,050 And then I'm also going to actually create a constant for the message when the machine is out of something 165 00:11:25,050 --> 00:11:29,220 or the drink doesn't exist, we can just call it out of range. 166 00:11:29,700 --> 00:11:34,950 Anyways, what we could do inside of our on button click function is we can check. 167 00:11:35,690 --> 00:11:43,190 If stringlength of the output box dot text. 168 00:11:43,580 --> 00:11:52,130 If this is less than max characters, then we can set the output box dot text equal to itself. 169 00:11:54,070 --> 00:12:01,900 And concatenate the string dot upper or get the upper variant of button dot name. 170 00:12:02,260 --> 00:12:07,540 And this is just in case we didn't name one of these particular strings here in upper case. 171 00:12:07,540 --> 00:12:13,480 So if they put n then it'll make sure the output box text isn't greater than 25 characters. 172 00:12:13,480 --> 00:12:16,810 And then it'll concatenate that letter into the output box. 173 00:12:16,810 --> 00:12:17,590 Text. 174 00:12:17,920 --> 00:12:23,800 The next button we could listen to inside of our image label is the space button. 175 00:12:24,830 --> 00:12:31,520 So what we want to happen when we click on our space button. 176 00:12:32,110 --> 00:12:37,360 Well, what we could do is first make sure the debounce is not active. 177 00:12:38,210 --> 00:12:44,180 And now we can basically do the same thing that we did inside of our on button clicked function. 178 00:12:44,570 --> 00:12:50,480 We can make sure that the length of the current output box is text is under 25. 179 00:12:50,480 --> 00:12:56,390 Make sure to play the click sound, and instead of concatenating the name of this button, what we're 180 00:12:56,390 --> 00:13:00,500 going to do is we're just going to concatenate an empty space. 181 00:13:00,500 --> 00:13:03,890 So we'll just have a string with nothing inside of it. 182 00:13:04,560 --> 00:13:08,550 The next one we could do is inside of our frames image label. 183 00:13:08,640 --> 00:13:11,130 We'll wait for the backspace button. 184 00:13:11,790 --> 00:13:15,060 And what do we want to do when this is pressed? 185 00:13:15,990 --> 00:13:21,420 Well what we could do for this one is basically do the exact same things here. 186 00:13:21,420 --> 00:13:27,600 Make sure the debounce isn't active, play the sound, and instead, since we're backspacing or removing 187 00:13:27,600 --> 00:13:34,710 a character from our output box text, we can use the string dot sub function to get a substring of 188 00:13:34,710 --> 00:13:37,170 output box dot text. 189 00:13:38,240 --> 00:13:44,660 And the length is going to be from the first index of our string to the string dot length. 190 00:13:44,990 --> 00:13:50,210 Output box dot text minus one. 191 00:13:50,210 --> 00:13:56,630 So basically we're getting all of the characters from the first index all the way to the second to last 192 00:13:56,630 --> 00:13:57,440 index. 193 00:13:57,920 --> 00:14:03,740 So if we typed in something like hello and we hit backspace, then we'll just get hell. 194 00:14:03,740 --> 00:14:07,790 If we hit backspace again then we'll just get hell and so on. 195 00:14:08,270 --> 00:14:11,990 The next button we need to listen to of course is our enter button. 196 00:14:11,990 --> 00:14:15,890 So frame dot image label wait for enter. 197 00:14:16,810 --> 00:14:18,610 Mouse button one up. 198 00:14:18,610 --> 00:14:20,500 You could use mouse button click as well. 199 00:14:20,500 --> 00:14:22,240 It doesn't really matter that much. 200 00:14:22,240 --> 00:14:25,930 And inside of this one again we want to verify the exact same thing. 201 00:14:25,930 --> 00:14:28,630 Make sure the debounce is not active. 202 00:14:28,630 --> 00:14:34,150 Otherwise, if the Debounce isn't active, this is where we're going to set it to true, because when 203 00:14:34,150 --> 00:14:39,880 the player hits enter, we want to check if this drink they inputted exists, and if it does, we want 204 00:14:39,880 --> 00:14:45,250 to dispense that drink out, and then we'll enable the debounce so we won't be able to manipulate the 205 00:14:45,250 --> 00:14:47,320 output box's text anymore. 206 00:14:47,320 --> 00:14:51,910 So this is where we can create some variables for our, uh, remote function. 207 00:14:51,910 --> 00:14:54,520 So we can have one called success. 208 00:14:54,520 --> 00:14:59,020 And then the remote function we're going to use the check for drink action. 209 00:14:59,020 --> 00:15:06,610 So if we actually go back to our drink class on the server we're going to get returned three different 210 00:15:06,610 --> 00:15:06,910 things. 211 00:15:06,910 --> 00:15:12,730 We're going to get returned, uh, whether or not it was successful, the name or key for the drink, 212 00:15:12,730 --> 00:15:15,250 and then all of the information for the drink. 213 00:15:15,250 --> 00:15:17,290 So we can have one called success. 214 00:15:17,290 --> 00:15:19,270 We can have one called drink name. 215 00:15:19,270 --> 00:15:21,880 And then the properties for this particular drink. 216 00:15:21,880 --> 00:15:27,310 And we're going to use the request drink function and invoke to the server. 217 00:15:27,310 --> 00:15:29,290 We want to check for a drink. 218 00:15:29,290 --> 00:15:31,330 And what drink do we want to check for. 219 00:15:31,330 --> 00:15:35,860 Well we want to check for the one that was inputted inside of our output box. 220 00:15:36,340 --> 00:15:44,260 And the way to do that would be to use string dot lower, because the output box's text is going to 221 00:15:44,260 --> 00:15:45,340 be all in uppercase. 222 00:15:45,340 --> 00:15:47,290 So we want to make sure it's lowercase. 223 00:15:47,710 --> 00:15:51,220 And then we could do output box dot text. 224 00:15:51,220 --> 00:15:56,860 So if we typed in something like uh juice then it'll make it all lowercase. 225 00:15:56,860 --> 00:15:59,470 And then it's going to request for the server to check. 226 00:15:59,470 --> 00:16:03,910 And it's going to look to see if a particular drink has this string. 227 00:16:03,910 --> 00:16:08,050 So for every possible name it's going to check if it has something like that. 228 00:16:08,050 --> 00:16:10,780 Then it's going to return that particular drink to us. 229 00:16:11,490 --> 00:16:15,120 And then we can just easily check if success. 230 00:16:15,120 --> 00:16:19,620 Then we can call the dispense drink function and dispense the drink out. 231 00:16:20,390 --> 00:16:26,930 Otherwise, what we could do is we could set the output box dot text equal to the output message or 232 00:16:26,930 --> 00:16:32,030 out of range, and then we could make the out of range message blink a couple of times if we like. 233 00:16:32,030 --> 00:16:34,910 So we could have a for loop that just loops three times. 234 00:16:38,270 --> 00:16:43,070 Then we could wait for some arbitrary amount of time, like 0.5 seconds. 235 00:16:43,830 --> 00:16:49,050 And then we can do output box dot text transparency. 236 00:16:50,040 --> 00:16:52,590 We can set it to one to make it invisible. 237 00:16:52,590 --> 00:16:58,170 And then we can wait again for another 0.5 seconds and then set it to be visible again. 238 00:17:00,090 --> 00:17:05,940 And once that for loop is finished, we can just set output box dot text back to be nothing again and 239 00:17:05,940 --> 00:17:08,580 we'll set Debounce back to false. 240 00:17:09,200 --> 00:17:14,570 So some events we want to listen to for the player is when a child gets added to the backpack. 241 00:17:14,570 --> 00:17:21,560 So child added we want to connect our on child added to backpack function and make a reference to it. 242 00:17:21,920 --> 00:17:26,600 We also want to listen for when a child gets added to the player itself. 243 00:17:29,340 --> 00:17:34,980 And the thing we want to listen to that gets added to our player is actually the backpack folder. 244 00:17:35,220 --> 00:17:42,690 And this is because since our GUI has the reset on spawn property disabled, this guy is going to be 245 00:17:42,690 --> 00:17:43,650 here forever. 246 00:17:43,650 --> 00:17:47,730 So that means let's say the player dies and their character respawns. 247 00:17:47,730 --> 00:17:53,130 Well, when that happens, their backpack folder actually gets deleted and a new one gets set in its 248 00:17:53,130 --> 00:17:53,790 place. 249 00:17:53,790 --> 00:18:00,690 So that means when that happens, we got to reattach the on child added to backpack event to this new 250 00:18:00,690 --> 00:18:01,800 backpack item. 251 00:18:01,800 --> 00:18:06,090 So that's why we got to listen for when a new child gets added to our player object, which would be 252 00:18:06,090 --> 00:18:07,470 the backpack folder. 253 00:18:07,470 --> 00:18:12,360 So we could make sure that whatever child is being added to our player is the backpack folder. 254 00:18:12,360 --> 00:18:18,870 So if child dot name is not equal to backpack, then we're just going to return because we don't care 255 00:18:18,870 --> 00:18:19,290 about it. 256 00:18:19,290 --> 00:18:25,860 However, if it is the backpack, then we can do the exact same thing here and we'll just replace this 257 00:18:25,860 --> 00:18:27,240 with child. 258 00:18:27,900 --> 00:18:32,250 And then one last thing I want to make sure to do is I want to listen for when a character gets added 259 00:18:32,250 --> 00:18:33,300 to my player. 260 00:18:34,670 --> 00:18:37,190 Get that character in our lambda function. 261 00:18:38,080 --> 00:18:43,000 And then I want to make sure to update our local character property equal to this new character, because 262 00:18:43,000 --> 00:18:48,400 again, the script is going to exist forever because our gene does not get reset when a player dies. 263 00:18:48,400 --> 00:18:52,690 And we want to constantly update the character variable just in case the player dies. 264 00:18:52,720 --> 00:18:55,420 Now we can go ahead and fill out these two functions. 265 00:18:55,420 --> 00:19:00,370 So the first one we could do is on child added to backpack, which should be relatively straightforward. 266 00:19:00,370 --> 00:19:06,730 What we're going to do is we want to make sure that whatever child is being added to the backpack is 267 00:19:06,730 --> 00:19:07,540 a tool. 268 00:19:07,540 --> 00:19:14,800 So if not child is a tool, then we're just going to return. 269 00:19:15,720 --> 00:19:22,230 Uh, another thing we want to check is if this tool has the git attribute, the drink id. 270 00:19:22,230 --> 00:19:28,440 So if this tool does not have this ID so if not ID then we're going to return as well because we don't 271 00:19:28,440 --> 00:19:29,580 care about this tool. 272 00:19:29,580 --> 00:19:33,090 Otherwise if it does have the ID then it is a drink object. 273 00:19:33,090 --> 00:19:38,010 And we want to create a new drink object on the client in case we haven't already. 274 00:19:38,010 --> 00:19:40,590 So that's where the drink class comes into play. 275 00:19:40,590 --> 00:19:44,340 We can call the constructor, we can pass the guy. 276 00:19:44,790 --> 00:19:50,820 And if you remember, the second one we have to pass would be the particular key for this drink. 277 00:19:50,820 --> 00:19:55,500 But since we're going to be using the ID for this drink, I don't really care about this drink name 278 00:19:55,500 --> 00:19:55,980 property. 279 00:19:55,980 --> 00:19:58,350 So I can just pass an empty string. 280 00:19:58,350 --> 00:20:04,950 Or in this case I'll just do child dot uh, name because I really want to pass the ID that is stored 281 00:20:04,950 --> 00:20:09,540 for this object, because when we call this constructor, it's going to check whether or not it has 282 00:20:09,540 --> 00:20:15,780 an ID, and if it does, then it's going to get an object from the server that has this particular ID. 283 00:20:16,500 --> 00:20:18,630 And then inside of the dispense drink function. 284 00:20:18,630 --> 00:20:23,940 What I actually want to do is I want to have the key or the drink name for this particular drink passed 285 00:20:23,940 --> 00:20:27,000 to the function, as well as the properties for the function. 286 00:20:27,000 --> 00:20:33,240 So when we actually call this function down here, I want to be able to pass the drink name and the 287 00:20:33,240 --> 00:20:34,800 properties for the drink. 288 00:20:34,800 --> 00:20:40,080 And then from this point, using those properties, what I'm going to do is I'm going to set the output 289 00:20:40,080 --> 00:20:44,370 box dot text equal to the properties. 290 00:20:44,370 --> 00:20:47,160 And we're going to get the dispense message. 291 00:20:47,160 --> 00:20:50,310 So dot dispense message. 292 00:20:51,200 --> 00:20:55,160 So that's going to be whatever the dispensed message is for that particular drink. 293 00:20:55,160 --> 00:21:00,440 So if I go into pre-made drinks, if I got a cup of air, the dispense message would just be the default 294 00:21:00,440 --> 00:21:01,640 of dispensing. 295 00:21:02,120 --> 00:21:08,780 And then from this point I could do properties dot get the dispense sound and play that. 296 00:21:09,020 --> 00:21:12,200 And then I'm going to wait for that dispense sound to end. 297 00:21:12,200 --> 00:21:15,140 So dispense sound dot ended. 298 00:21:15,140 --> 00:21:17,000 We'll wait for that event to fire. 299 00:21:17,000 --> 00:21:24,710 And when it does then we can use the comms event and we can fire to the server to create a drink object. 300 00:21:25,200 --> 00:21:29,880 And the drink object we want to create is going to be this particular key. 301 00:21:30,060 --> 00:21:34,800 So the server will go create that drink object and add it to our backpack. 302 00:21:34,800 --> 00:21:40,290 And when it gets added to our backpack then that's when this event down here gets fired and calls the 303 00:21:40,290 --> 00:21:42,300 on child added to backpack. 304 00:21:42,750 --> 00:21:47,490 And then from that point, once we've dispensed our drink, then we can close out the GUI. 305 00:21:47,490 --> 00:21:52,860 So we dispense our drink and then once it gets dispensed and placed in our inventory, we can close 306 00:21:52,860 --> 00:21:54,420 the GUI on our end. 307 00:21:55,300 --> 00:21:55,720 All right. 308 00:21:55,720 --> 00:21:57,250 Seems pretty good so far. 309 00:21:57,250 --> 00:22:02,380 And in fact, since we're using this constant out of range here inside of our local script, I don't 310 00:22:02,380 --> 00:22:05,290 think we actually need it to exist within. 311 00:22:05,290 --> 00:22:05,890 Where was it? 312 00:22:05,890 --> 00:22:08,500 Yeah, inside of our pre-made drinks module script. 313 00:22:08,500 --> 00:22:12,250 We don't need it in here, so I'll just delete that. 314 00:22:12,550 --> 00:22:14,200 And otherwise we're almost finished. 315 00:22:14,200 --> 00:22:18,760 The last thing we need to do is set up our server script and make some drinks. 316 00:22:18,760 --> 00:22:20,740 So I'll see you in the next lecture.